package com.situ.blog.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.situ.blog.dao.IBlogDao;
import com.situ.blog.dao.impl.BlogDaoImpl;
import com.situ.blog.pojo.Blog;

import java.util.Map;

public class BlogExcelListener extends AnalysisEventListener<Blog> {
    private IBlogDao blogDao = new BlogDaoImpl();

    //一行一行读取excel中内容
    @Override
    public void invoke(Blog blog, AnalysisContext context) {
        System.out.println(blog);
        blogDao.addExcel(blog);
    }

    //读取表头的数据
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头数据： " + headMap);
    }

    //读取所有数据完之后执行这个方法
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        System.out.println("ExcelListener.doAfterAllAnalysed");
    }
}
